package com.newspublish.system.controller;

import com.newspublish.system.entity.system.SysUser;
import com.newspublish.system.service.SysUserService;
import com.newspublish.system.utils.result.Result;
import com.newspublish.system.utils.util.MD5;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "注册")
@RequestMapping("/admin/user")
public class RegisterController {

    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value="用户注册模块")
    @PostMapping("/register")
    public Result register(@RequestBody SysUser sysUser){

        //对输入的密码进行加密
        String encrypt= MD5.encrypt(sysUser.getPassword());
        sysUser.setPassword(encrypt);
        boolean is_success=sysUserService.save(sysUser);
        if(is_success){
            return Result.ok().message("注册新用户成功");
        }else{
            return Result.fail().message("注册新用户失败");
        }

    }

}
